package common.inter;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;

import model.Wxuser;

public class WxUserInter implements Interceptor{

	@Override
	public void intercept(Invocation inv) {
		Controller con = inv.getController() ;
		String token = con.getRequest().getHeader("token");
		if (StrKit.isBlank(token)) {
			con.renderJson(Ret.fail("state","needLogin"));
			return ;
		}
		Wxuser wxuser = Wxuser.dao.findFirstByToken(token);
		if (null == wxuser) {
			con.renderJson(Ret.fail("state","needLogin"));
			return ;
		}
		con.set("wxuser", wxuser);
		inv.invoke(); 
		con.removeAttr("wxuser");
	}

}
